<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- <button>按钮</button>
  <script>
    const btn = document.querySelector('button');
    // 赋值点击事件
    btn.onclick = () => {
      alert('点击了')
    };
    // 追加点击事件
    btn.addEventListener('click', () => {
      alert('点击了1111')
    });
  </script> -->


  <div class="box" style="width: 100px; height: 100px;background-color: aqua;">div 标签</div>
  <input type="text">

  <script>
    const div = document.querySelector('div')

    const box = document.querySelector('.box')
    box.addEventListener('mouseenter', function () {
      console.log('鼠标移入了')
    })
    box.addEventListener('mouseleave', function () {
      console.log('鼠标移出了')
    })

    div.addEventListener('mouseenter', function () {
      this.style.backgroundColor = 'green'
    })
    div.addEventListener('mouseleave', function () {
      this.style.backgroundColor = ''
    })



    const text = document.querySelector('input')

    text.addEventListener('focus', function () {
      console.log('获取焦点')
    })
    text.addEventListener('blur', function () {
      console.log('失去焦点')
    })


    // 4. input监听value值改变
    text.addEventListener('input', function () {
      console.log(this.value)
    })
  </script>
</body>

</html>